<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="允许填报" prop="fcreationdate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.fcreationdate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择允许填报">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="允许填报" prop="fcreateby">
        <el-input
          v-model="queryParams.fcreateby"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="flastupdatedate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.flastupdatedate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择允许填报">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="允许填报" prop="flastupdateby">
        <el-input
          v-model="queryParams.flastupdateby"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fromname">
        <el-input
          v-model="queryParams.fromname"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fromcode">
        <el-input
          v-model="queryParams.fromcode"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fromcontent">
        <el-input
          v-model="queryParams.fromcontent"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fromdesignjson">
        <el-input
          v-model="queryParams.fromdesignjson"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="defaultdata">
        <el-input
          v-model="queryParams.defaultdata"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fpagecontroljson">
        <el-input
          v-model="queryParams.fpagecontroljson"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="fremarks">
        <el-input
          v-model="queryParams.fremarks"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="controltitle">
        <el-input
          v-model="queryParams.controltitle"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1 列表表单，2编辑表单 3流程表单" prop="fromtype">
        <el-select v-model="queryParams.fromtype" placeholder="请选择1 列表表单，2编辑表单 3流程表单" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="1 列表表单，2编辑表单 3流程表单" prop="nodepower">
        <el-input
          v-model="queryParams.nodepower"
          placeholder="请输入1 列表表单，2编辑表单 3流程表单"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保存表名" prop="fromTableName">
        <el-input
          v-model="queryParams.fromTableName"
          placeholder="请输入保存表名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="列表查询条件" prop="queryJson">
        <el-input
          v-model="queryParams.queryJson"
          placeholder="请输入列表查询条件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="弹出宽度设置" prop="dialogwidth">
        <el-input
          v-model="queryParams.dialogwidth"
          placeholder="请输入弹出宽度设置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="填报开始时间" prop="startDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择填报开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="填报结束时间" prop="endDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择填报结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="提交截止时间" prop="modifyEndDate">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.modifyEndDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择提交截止时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="显示截止时间" prop="showEndDate">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.showEndDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择显示截止时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="白名单限制" prop="isWhite">
        <el-input
          v-model="queryParams.isWhite"
          placeholder="请输入白名单限制"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许修改" prop="isModify">
        <el-input
          v-model="queryParams.isModify"
          placeholder="请输入允许修改"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="网上确认" prop="isNetconfirm">
        <el-input
          v-model="queryParams.isNetconfirm"
          placeholder="请输入是否网上确认"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="允许填报" prop="isInput">
        <el-input
          v-model="queryParams.isInput"
          placeholder="请输入允许填报"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['grant:tappfrom:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['grant:tappfrom:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['grant:tappfrom:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['grant:tappfrom:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tappfromList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="允许填报" align="center" prop="fid" />
      <el-table-column label="允许填报" align="center" prop="fcreationdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fcreationdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="允许填报" align="center" prop="fcreateby" />
      <el-table-column label="允许填报" align="center" prop="flastupdatedate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.flastupdatedate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="允许填报" align="center" prop="flastupdateby" />
      <el-table-column label="允许填报" align="center" prop="fromname" />
      <el-table-column label="允许填报" align="center" prop="fromcode" />
      <el-table-column label="允许填报" align="center" prop="fromcontent" />
      <el-table-column label="允许填报" align="center" prop="fromdesignjson" />
      <el-table-column label="允许填报" align="center" prop="defaultdata" />
      <el-table-column label="允许填报" align="center" prop="fpagecontroljson" />
      <el-table-column label="允许填报" align="center" prop="fremarks" />
      <el-table-column label="允许填报" align="center" prop="controltitle" />
      <el-table-column label="1 列表表单，2编辑表单 3流程表单" align="center" prop="fromtype" />
      <el-table-column label="1 列表表单，2编辑表单 3流程表单" align="center" prop="nodepower" />
      <el-table-column label="保存表名" align="center" prop="fromTableName" />
      <el-table-column label="列表查询条件" align="center" prop="queryJson" />
      <el-table-column label="弹出宽度设置" align="center" prop="dialogwidth" />
      <el-table-column label="填报开始时间" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="填报结束时间" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="提交截止时间" align="center" prop="modifyEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="显示截止时间" align="center" prop="showEndDate" width="180">
      <template slot-scope="scope">
        <span>{{ parseTime(scope.row.showEndDate, '{y}-{m}-{d}') }}</span>
      </template>
    </el-table-column>
      <el-table-column label="白名单限制" align="center" prop="isWhite" />
      <el-table-column label="允许修改" align="center" prop="isModify" />
      <el-table-column label="网上确认" align="center" prop="isNetconfirm" />
      <el-table-column label="允许填报" align="center" prop="isInput" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['grant:tappfrom:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['grant:tappfrom:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报名表单管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="允许填报" prop="fcreationdate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.fcreationdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择允许填报">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="允许填报" prop="fcreateby">
          <el-input v-model="form.fcreateby" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="flastupdatedate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.flastupdatedate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择允许填报">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="允许填报" prop="flastupdateby">
          <el-input v-model="form.flastupdateby" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fromname">
          <el-input v-model="form.fromname" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fromcode">
          <el-input v-model="form.fromcode" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fromcontent">
          <el-input v-model="form.fromcontent" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fromdesignjson">
          <el-input v-model="form.fromdesignjson" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="defaultdata">
          <el-input v-model="form.defaultdata" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fpagecontroljson">
          <el-input v-model="form.fpagecontroljson" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="fremarks">
          <el-input v-model="form.fremarks" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="允许填报" prop="controltitle">
          <el-input v-model="form.controltitle" placeholder="请输入允许填报" />
        </el-form-item>
        <el-form-item label="1 列表表单，2编辑表单 3流程表单">
          <el-select v-model="form.fromtype" placeholder="请选择1 列表表单，2编辑表单 3流程表单">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="1 列表表单，2编辑表单 3流程表单" prop="nodepower">
          <el-input v-model="form.nodepower" placeholder="请输入1 列表表单，2编辑表单 3流程表单" />
        </el-form-item>
        <el-form-item label="保存表名" prop="fromTableName">
          <el-input v-model="form.fromTableName" placeholder="请输入保存表名" />
        </el-form-item>
        <el-form-item label="列表查询条件" prop="queryJson">
          <el-input v-model="form.queryJson" placeholder="请输入列表查询条件" />
        </el-form-item>
        <el-form-item label="弹出宽度设置" prop="dialogwidth">
          <el-input v-model="form.dialogwidth" placeholder="请输入弹出宽度设置" />
        </el-form-item>
        <el-form-item label="填报开始时间" prop="startDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.startDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择填报开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="填报结束时间" prop="endDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.endDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择填报结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="提交截止时间" prop="modifyEndDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.modifyEndDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择提交截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="显示截止时间" prop="showEndDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.showEndDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择显示截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="白名单限制" prop="isWhite">
          <el-input v-model="form.isWhite" placeholder="请输入白名单限制" />
        </el-form-item>
        <el-form-item label="允许修改" prop="isModify">
          <el-input v-model="form.isModify" placeholder="请输入允许修改" />
        </el-form-item>
        <el-form-item label="网上确认" prop="isModify">
          <el-input v-model="form.isNetconfirm" placeholder="请输入是否网上确认" />
        </el-form-item>
        <el-form-item label="允许填报" prop="isInput">
          <el-input v-model="form.isInput" placeholder="请输入允许填报" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTappfrom, getTappfrom, delTappfrom, addTappfrom, updateTappfrom, exportTappfrom } from "@/api/grant/tappfrom";

export default {
  name: "Tappfrom",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 报名表单管理表格数据
      tappfromList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fcreationdate: undefined,
        fcreateby: undefined,
        flastupdatedate: undefined,
        flastupdateby: undefined,
        fromname: undefined,
        fromcode: undefined,
        fromcontent: undefined,
        fromdesignjson: undefined,
        defaultdata: undefined,
        fpagecontroljson: undefined,
        fremarks: undefined,
        controltitle: undefined,
        fromtype: undefined,
        nodepower: undefined,
        fromTableName: undefined,
        queryJson: undefined,
        dialogwidth: undefined,
        startDate: undefined,
        endDate: undefined,
        isWhite: undefined,
        isModify: undefined,
        isInput: undefined,
        modifyEndDate: undefined,
        showEndDate:undefined,
        isNetconfirm:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询报名表单管理列表 */
    getList() {
      this.loading = true;
      listTappfrom(this.queryParams).then(response => {
        this.tappfromList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fid: undefined,
        fcreationdate: undefined,
        fcreateby: undefined,
        flastupdatedate: undefined,
        flastupdateby: undefined,
        fromname: undefined,
        fromcode: undefined,
        fromcontent: undefined,
        fromdesignjson: undefined,
        defaultdata: undefined,
        fpagecontroljson: undefined,
        fremarks: undefined,
        controltitle: undefined,
        fromtype: undefined,
        nodepower: undefined,
        fromTableName: undefined,
        queryJson: undefined,
        dialogwidth: undefined,
        startDate: undefined,
        endDate: undefined,
        isWhite: undefined,
        isModify: undefined,
        isInput: undefined,
        modifyEndDate: undefined,
        showEndDate:undefined,
        isNetconfirm: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fid)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报名表单管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fid = row.fid || this.ids
      getTappfrom(fid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报名表单管理";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fid != undefined) {
            updateTappfrom(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTappfrom(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fids = row.fid || this.ids;
      this.$confirm('是否确认删除报名表单管理编号为"' + fids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTappfrom(fids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报名表单管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTappfrom(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
